package Demo;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;

import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.Platform;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;

public class DemoClass {
	
WebDriver myWD;
	//System.setProperty("webdriver.chrome.driver", )


/*	public void beforelaunchBrowser() throws Exception
	{
		//System.setProperty("webdriver.chrome.driver", "C:\\Manjusha\\Selenium\\ChromeDriver\\chromedriver.exe");
		//myWD = new FirefoxDriver();
	
	myWD = new RemoteWebDriver(new URL("http://localhost:".concat(port).concat("/wd/hub")), capabilites);
	}*/
	
@BeforeMethod
@Parameters({"browser"})
public void launchBrowser(@Optional("FF") String browser) throws Exception
{
	if(browser.equalsIgnoreCase("FF")){
		//myWD = new FirefoxDriver();
		/*DesiredCapabilities capabilites = new DesiredCapabilities();
		capabilites.setBrowserName(browser);
		capabilites.setPlatform(Platform.WINDOWS);*/
		try {
		//myWD = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), capabilites );
			myWD = new FirefoxDriver();
		}
		catch (Exception e) {
		    
			   e.printStackTrace();
			  }
	}
	else if(browser.equalsIgnoreCase("Chrome")){
		System.setProperty("webdriver.chrome.driver", "C:\\Manjusha\\Selenium\\ChromeDriver\\chromedriver.exe");
		myWD = new ChromeDriver();
	}
	else if(browser.equalsIgnoreCase("IE")){
		System.setProperty("webdriver.ie.driver", "C:\\Manjusha\\Selenium\\IE\\IEDriverServer.exe");
		myWD = new InternetExplorerDriver();
	}
	
}

/*@AfterMethod

public void closeBrowser(ITestResult result) throws IOException {
	
	if (!result.isSuccess()) {
		
	File imageFile = ((TakesScreenshot) myWD)
.getScreenshotAs(OutputType.FILE);
	
		String failureImageFileName = result.getMethod().getMethodName()+ new SimpleDateFormat("MM-dd-yyyy_HH-ss").format(new GregorianCalendar().getTime())+ ".png";
		
	File failureImageFile = new File(failureImageFileName);
		
	FileUtils.moveFile(imageFile, failureImageFile);
	
	}
	
	myWD.close();
	
	myWD.quit();

	}*/




	/*@After
	public void aftercloseBrowser()
	{
		myWD.close();
		myWD.quit();
	}*/
}
